/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef _BOARD_CONFIG_H_
#define _BOARD_CONFIG_H_

#ifdef __cplusplus
 extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx_hal.h"

typedef enum {
  BUTTON_KEY = 0,
} Button_TypeDef;

typedef enum {
  BUTTON_MODE_GPIO = 0,
  BUTTON_MODE_EXTI = 1
} ButtonMode_TypeDef;

/** @addtogroup STM32F4_DISCOVERY_LOW_LEVEL_LED
  * @{
  */
#define LEDn	4	/* required */

#define LED1_PIN                         GPIO_PIN_12
#define LED1_GPIO_PORT                   GPIOD
#define LED1_GPIO_CLK_ENABLE()           __GPIOD_CLK_ENABLE()
#define LED1_GPIO_CLK_DISABLE()          __GPIOD_CLK_DISABLE()

#define LED2_PIN                         GPIO_PIN_13
#define LED2_GPIO_PORT                   GPIOD
#define LED2_GPIO_CLK_ENABLE()           __GPIOD_CLK_ENABLE()
#define LED2_GPIO_CLK_DISABLE()          __GPIOD_CLK_DISABLE()

#define LED3_PIN                         GPIO_PIN_14
#define LED3_GPIO_PORT                   GPIOD
#define LED3_GPIO_CLK_ENABLE()           __GPIOD_CLK_ENABLE()
#define LED3_GPIO_CLK_DISABLE()          __GPIOD_CLK_DISABLE()

#define LED4_PIN                         GPIO_PIN_15
#define LED4_GPIO_PORT                   GPIOD
#define LED4_GPIO_CLK_ENABLE()           __GPIOD_CLK_ENABLE()
#define LED4_GPIO_CLK_DISABLE()          __GPIOD_CLK_DISABLE()

/** @addtogroup STM32F4_DISCOVERY_LOW_LEVEL_BUTTON
  * @{
  */
#define BUTTONn		0

/**
 * @brief Wakeup push-button
 */
#define KEY_BUTTON_PIN                GPIO_PIN_0
#define KEY_BUTTON_GPIO_PORT          GPIOA
#define KEY_BUTTON_GPIO_CLK_ENABLE()  __GPIOA_CLK_ENABLE()
#define KEY_BUTTON_GPIO_CLK_DISABLE() __GPIOA_CLK_DISABLE()
#define KEY_BUTTON_EXTI_IRQn          EXTI0_IRQn


#define BUTTONx_GPIO_CLK_ENABLE(__INDEX__)    (KEY_BUTTON_GPIO_CLK_ENABLE())

#define BUTTONx_GPIO_CLK_DISABLE(__INDEX__)    (KEY_BUTTON_GPIO_CLK_DISABLE())

/** @addtogroup STM32F4_DISCOVERY_LOW_LEVEL_BUS
  * @{
  */

#define BOARD_SPIn	1
/*##################### board SPI1 ###################################*/
#define BOARD_SPI1				SPI1
#define BOARD_SPI1_CLK_ENABLE()			__SPI1_CLK_ENABLE()
#define BOARD_SPI1_AF				GPIO_AF5_SPI1

#define BOARD_SPI1_FORCE_RESET()               __HAL_RCC_SPI1_FORCE_RESET()
#define BOARD_SPI1_RELEASE_RESET()             __HAL_RCC_SPI1_RELEASE_RESET()

#define BOARD_SPI1_SCK_PIN			GPIO_PIN_5
#define BOARD_SPI1_SCK_GPIO_PORT		GPIOA
#define BOARD_SPI1_SCK_GPIO_CLK_ENABLE()	__GPIOA_CLK_ENABLE()

#define BOARD_SPI1_MISO_PIN			GPIO_PIN_6
#define BOARD_SPI1_MISO_GPIO_PORT		GPIOA
#define BOARD_SPI1_MISO_GPIO_CLK_ENABLE()	__GPIOA_CLK_ENABLE()

#define BOARD_SPI1_MOSI_PIN			GPIO_PIN_7
#define BOARD_SPI1_MOSI_GPIO_PORT		GPIOA
#define BOARD_SPI1_MOSI_GPIO_CLK_ENABLE()	__GPIOA_CLK_ENABLE()

/*####################### BOARD SPI1 DMA #############################*/
#define BOARD_SPI1_DMA_CLK_ENABLE()             __HAL_RCC_DMA2_CLK_ENABLE()
#define BOARD_SPI1_TX_DMA_CHANNEL		DMA_CHANNEL_3
#define BOARD_SPI1_TX_DMA_STREAM		DMA2_Stream3
#define BOARD_SPI1_RX_DMA_CHANNEL		DMA_CHANNEL_3
#define BOARD_SPI1_RX_DMA_STREAM		DMA2_Stream0

#define BOARD_SPI1_DMA_TX_IRQn                 DMA2_Stream3_IRQn
#define BOARD_SPI1_DMA_RX_IRQn                 DMA2_Stream0_IRQn
#define BOARD_SPI1_DMA_TX_IRQHandler           DMA2_Stream3_IRQHandler
#define BOARD_SPI1_DMA_RX_IRQHandler           DMA2_Stream0_IRQHandler

/*####################### devices' cs pin ############################*/
#if BOARD_SPIn > 0
#define BOARD_SPI_DEVn				3

#define BOARD_SPI_DEV1_CS_PIN			GPIO_PIN_7
#define BOARD_SPI_DEV1_CS_GPIO_PORT		GPIOB
#define BOARD_SPI_DEV1_CS_GPIO_CLK_ENABLE()	__GPIOB_CLK_ENABLE()

#define BOARD_SPI_DEV2_CS_PIN			GPIO_PIN_3
#define BOARD_SPI_DEV2_CS_GPIO_PORT		GPIOE
#define BOARD_SPI_DEV2_CS_GPIO_CLK_ENABLE()	__GPIOE_CLK_ENABLE()

#define BOARD_SPI_DEV3_CS_PIN			GPIO_PIN_4
#define BOARD_SPI_DEV3_CS_GPIO_PORT		GPIOA
#define BOARD_SPI_DEV3_CS_GPIO_CLK_ENABLE()	__GPIOA_CLK_ENABLE()

#define MPU9250_SPI		1
#define MPU9250_CS_PIN		1

#define LIS302DL_SPI		1
#define LIS302DL_CS_PIN		2

#define ADXL345_SPI		1
#define ADXL345_CS_PIN		3

#endif

/*##################### EVENT TRIGGER TIMER ####################*/
#define TRIGGER_TIMER		TIM7
#define TRIGGER_FREQ		1000
#define TRIGGER_TIMER_CLK_ENABLE()		__HAL_RCC_TIM7_CLK_ENABLE()
#define TRIGGER_TIMER_IRQn                      TIM7_IRQn
#define TRIGGER_TIMER_IRQHandler                TIM7_IRQHandler

#define BOARD_UARTn	1
/*###################### BOARD UART1 ##########################*/
#if 0
#define BOARD_UART1                           USART2
#define BOARD_UART1_CLK_ENABLE()              __HAL_RCC_USART2_CLK_ENABLE();

#define BOARD_UART1_FORCE_RESET()             __HAL_RCC_USART2_FORCE_RESET()
#define BOARD_UART1_RELEASE_RESET()           __HAL_RCC_USART2_RELEASE_RESET()

/* Definition for USARTx Pins */
#define BOARD_UART1_TX_GPIO_CLK_ENABLE()      __HAL_RCC_GPIOA_CLK_ENABLE()
#define BOARD_UART1_TX_PIN                    GPIO_PIN_2
#define BOARD_UART1_TX_GPIO_PORT              GPIOA
#define BOARD_UART1_TX_AF                     GPIO_AF7_USART2
#define BOARD_UART1_RX_GPIO_CLK_ENABLE()      __HAL_RCC_GPIOA_CLK_ENABLE()
#define BOARD_UART1_RX_PIN                    GPIO_PIN_3
#define BOARD_UART1_RX_GPIO_PORT              GPIOA
#define BOARD_UART1_RX_AF                     GPIO_AF7_USART2

/*###################### BOARD UART1 DMA ######################*/
#define BOARD_UART1_DMA_CLK_ENABLE()                __HAL_RCC_DMA1_CLK_ENABLE()
/* Definition for USARTx's DMA */
#define BOARD_UART1_TX_DMA_CHANNEL            DMA_CHANNEL_4
#define BOARD_UART1_TX_DMA_STREAM             DMA1_Stream6
#define BOARD_UART1_RX_DMA_CHANNEL            DMA_CHANNEL_4
#define BOARD_UART1_RX_DMA_STREAM             DMA1_Stream5

/* Definition for USARTx's NVIC */
#define BOARD_UART1_DMA_TX_IRQn               DMA1_Stream6_IRQn
#define BOARD_UART1_DMA_RX_IRQn               DMA1_Stream5_IRQn
#define BOARD_UART1_DMA_TX_IRQHandler         DMA1_Stream6_IRQHandler
#define BOARD_UART1_DMA_RX_IRQHandler         DMA1_Stream5_IRQHandler
#define BOARD_UART1_IRQn                      USART2_IRQn
#define BOARD_UART1_IRQHandler                USART2_IRQHandler
#endif
/*###################### BOARD UART2 ##########################*/
#define BOARD_UART1                           USART1
#define BOARD_UART1_CLK_ENABLE()              __HAL_RCC_USART1_CLK_ENABLE();

#define BOARD_UART1_FORCE_RESET()             __HAL_RCC_USART1_FORCE_RESET()
#define BOARD_UART1_RELEASE_RESET()           __HAL_RCC_USART1_RELEASE_RESET()

/* Definition for USARTx Pins */
#define BOARD_UART1_TX_GPIO_CLK_ENABLE()      __HAL_RCC_GPIOA_CLK_ENABLE()
#define BOARD_UART1_TX_PIN                    GPIO_PIN_9
#define BOARD_UART1_TX_GPIO_PORT              GPIOA
#define BOARD_UART1_TX_AF                     GPIO_AF7_USART1
#define BOARD_UART1_RX_GPIO_CLK_ENABLE()      __HAL_RCC_GPIOA_CLK_ENABLE()
#define BOARD_UART1_RX_PIN                    GPIO_PIN_10
#define BOARD_UART1_RX_GPIO_PORT              GPIOA
#define BOARD_UART1_RX_AF                     GPIO_AF7_USART1

/*###################### BOARD UART2 DMA ######################*/
#define BOARD_UART1_DMA_CLK_ENABLE()          __HAL_RCC_DMA2_CLK_ENABLE()
/* Definition for USARTx's DMA */
#define BOARD_UART1_TX_DMA_CHANNEL            DMA_CHANNEL_4
#define BOARD_UART1_TX_DMA_STREAM             DMA2_Stream7
#define BOARD_UART1_RX_DMA_CHANNEL            DMA_CHANNEL_4
#define BOARD_UART1_RX_DMA_STREAM             DMA2_Stream5

/* Definition for USARTx's NVIC */
#define BOARD_UART1_DMA_TX_IRQn               DMA2_Stream7_IRQn
#define BOARD_UART1_DMA_RX_IRQn               DMA2_Stream5_IRQn
#define BOARD_UART1_DMA_TX_IRQHandler         DMA2_Stream7_IRQHandler
#define BOARD_UART1_DMA_RX_IRQHandler         DMA2_Stream5_IRQHandler
#define BOARD_UART1_IRQn                      USART1_IRQn
#define BOARD_UART1_IRQHandler                USART1_IRQHandler

#if BOARD_UARTn > 0
#define BOARD_STDIN_UART	1	/* must be smaller than BOARD_UARTn*/
#define BOARD_STDOUT_UART	1
#define BOARD_STDERR_UART	1

//#define BOARD_SBUS_UART		2
#endif

/* ###################### EEPROM ############################# */
#define FLASH_AS_EEPROM
#ifdef FLASH_AS_EEPROM
/* Base address of the Flash sectors */
#define ADDR_FLASH_SECTOR_0     ((uint32_t)0x08000000) /* Base @ of Sector 0, 16 Kbytes */
#define ADDR_FLASH_SECTOR_1     ((uint32_t)0x08004000) /* Base @ of Sector 1, 16 Kbytes */
#define ADDR_FLASH_SECTOR_2     ((uint32_t)0x08008000) /* Base @ of Sector 2, 16 Kbytes */
#define ADDR_FLASH_SECTOR_3     ((uint32_t)0x0800C000) /* Base @ of Sector 3, 16 Kbytes */
#define ADDR_FLASH_SECTOR_4     ((uint32_t)0x08010000) /* Base @ of Sector 4, 64 Kbytes */
#define ADDR_FLASH_SECTOR_5     ((uint32_t)0x08020000) /* Base @ of Sector 5, 128 Kbytes */
#define ADDR_FLASH_SECTOR_6     ((uint32_t)0x08040000) /* Base @ of Sector 6, 128 Kbytes */
#define ADDR_FLASH_SECTOR_7     ((uint32_t)0x08060000) /* Base @ of Sector 7, 128 Kbytes */
#define ADDR_FLASH_SECTOR_8     ((uint32_t)0x08080000) /* Base @ of Sector 8, 128 Kbytes */
#define ADDR_FLASH_SECTOR_9     ((uint32_t)0x080A0000) /* Base @ of Sector 9, 128 Kbytes */
#define ADDR_FLASH_SECTOR_10    ((uint32_t)0x080C0000) /* Base @ of Sector 10, 128 Kbytes */
#define ADDR_FLASH_SECTOR_11    ((uint32_t)0x080E0000) /* Base @ of Sector 11, 128 Kbytes */

#define EEPROM_PAGE_SIZE	(uint32_t)0x1000
#define EEPROM_SECTOR_SIZE	(uint32_t)0x4000

#define EEPROM_SECTOR0_BASE	ADDR_FLASH_SECTOR_1
#define EEPROM_SECTOR1_BASE	ADDR_FLASH_SECTOR_2

#define EEPROM_SECTOR0		FLASH_SECTOR_1
#define EEPROM_SECTOR1		FLASH_SECTOR_2

#define EEPROM_VOLTAGE_RANGE	VOLTAGE_RANGE_3
#endif

/*################### DAC  #########################*/
#define DAC_USED 0
#define DAC_TRIG_TIMER	TIM6
#define DAC_TRIG_TIMER_CLK_ENABLE()	__HAL_RCC_TIM6_CLK_ENABLE()
#define DAC_TRIG_TIMER_CLK_DISABLE()	__HAL_RCC_TIM6_CLK_DISABLE()

#define DAC_CHANNEL1_GPIO_CLK_ENABLE()	__HAL_RCC_GPIOA_CLK_ENABLE()
#define DAC_CHANNEL1_PIN	GPIO_PIN_4
#define DAC_CHANNEL1_GPIO_PORT	GPIOA

#define DAC_CHANNEL2_GPIO_CLK_ENABLE()	__HAL_RCC_GPIOA_CLK_ENABLE()
#define DAC_CHANNEL2_PIN	GPIO_PIN_5
#define DAC_CHANNEL2_GPIO_PORT	GPIOA

/*################### DAC DMA ##########################*/
#define DAC_DMA_CLK_ENABLE()    __HAL_RCC_DMA1_CLK_ENABLE()

#define DAC_DMA_CHANNEL1	DMA_CHANNEL_7
#define DAC_DMA_STREAM1		DMA1_Stream5
#define DAC_DMA_IRQn1		DMA1_Stream5_IRQn
#define DAC_DMA_IRQHandler1	DMA1_Stream5_IRQHandler

#define DAC_DMA_CHANNEL2	DMA_CHANNEL_7
#define DAC_DMA_STREAM2		DMA1_Stream6
#define DAC_DMA_IRQn2		DMA1_Stream6_IRQn
#define DAC_DMA_IRQHandler2	DMA1_Stream6_IRQHandler
/*##################### AUDIO ##########################*/
/**
  * @brief  AUDIO I2C Interface pins
  */
#define AUDIO_I2C_ADDRESS                     0x94
  
  /* Audio Reset Pin definition */
#define AUDIO_RESET_GPIO_CLK_ENABLE()         __GPIOD_CLK_ENABLE()
#define AUDIO_RESET_PIN                       GPIO_PIN_4
#define AUDIO_RESET_GPIO                      GPIOD
/**
  * @}
  */ 


/**
  * @}
  */ 

/** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_Exported_Macros
  * @{
  */  
/**
  * @}
  */ 


/** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_Exported_Functions
  * @{
  */
uint32_t BSP_GetVersion(void);
void            BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef Mode);
uint32_t        BSP_PB_GetState(Button_TypeDef Button);
/**
  * @}
  */
  
#ifdef __cplusplus
}
#endif

#endif /* __STM32F4_DISCOVERY_H */
/**
  * @}
  */ 

/**
  * @}
  */ 

/**
  * @}
  */

 
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

